var wid=$(window).width();
/** 2013-12-16 누적사용량 ie8 반응형 처리를 위해 추가된 부분 **/
jQuery(document).ready(function(){
	if (wid >= 1600)	 { listResize('l'); }
	else				 { listResize('s');  }
	go_topPos();	/*2014-02-13 서브 상단바로가기 버튼 위치 추가*/
});

/** 2013-12-16 누적사용량 ie8 반응형 처리를 위해 추가된 부분 **/
jQuery(window).resize(function(){
	go_topPos();	/*2014-02-13 서브 상단바로가기 버튼 위치 추가*/
	var cWid = jQuery(window).width();
	if (cWid >= 1600)
	{
		if (wid < 1600){			// 1600 이상에서 처리해주어야 할 일 
			listResize('l');
		}
	}
	else
	{
		if (wid >= 1600){		// 1600 이하에서 처리해 주어야 할 일
			listResize('s');
		}
	}
	wid = cWid;
});

function changeTrColor(trObj, oldColor, newColor) {
	oldColor = trObj.style.backgroundColor;
    trObj.style.backgroundColor = newColor;
    trObj.onmouseout = function(){
        trObj.style.backgroundColor = oldColor;
    }
}

function go_topPos(){
	var wW = jQuery(window).width();
	if(wW > 1600){
		jQuery('.sub footer .btn_top').css(
			{'left':'1504px'}
			
		);
	} else {
		if(wW > 1000){
			jQuery('.sub footer .btn_top').css(
				{'left':wW-96+'px'}
			);
		} else {
			jQuery('.sub footer .btn_top').css(
				{'left':'904px'}
			);
		}
	}

	

}
function listResize(){
	$('.accumulate li').each(function () {
			$(this).eq(0).css('margin-left','14px');
			$(this).removeClass('listStyle01 listStyle02');
			/*$(this).css('background','#f7f7f7');*/
		});
	if(wid<1600){
		$('.accumulate li:nth-child(3n+1)').each(function () {
			$(this).eq(0).css('margin-left','0');
			$(this).addClass('listStyle01');
		});
	}else{
		$('.accumulate li:nth-child(5n+1)').each(function () {
			$(this).eq(0).css('margin-left','0');
			$(this).addClass('listStyle02');
		});
	}
}

jQuery(document).ready(function(){
	/* lnb */
	jQuery('.lnb ul li.depth02').each(function() {
		if(jQuery(this).hasClass('on')){
			jQuery(this).prev('li.depth02').css("background","url('/images/common/bg_lnb_prev_line.gif') repeat-x 0 100%");
			jQuery(this).prev('li.depth03').css("background","url('/images/common/bg_lnb_prev_line.gif') repeat-x 0 100%");
		}
	});
	jQuery('.lnb ul li.depth03').each(function() {
		if(jQuery(this).hasClass('on')){
			jQuery(this).prev('li.depth02').css("background","url('/images/common/bg_lnb_prev_line.gif') repeat-x 0 100%");
			jQuery(this).prev('li.depth03').css("background","url('/images/common/bg_lnb_prev_line.gif') repeat-x 0 100%");
		}
	});

	/* sub : 누적 사용량 리스트*/
	listResize();

	/* sub : 목표대비 사용량 tooltip */
	$.fn.extend({
		toolTip:function(){
			var posX;
			var posY;
			var termY;
			this.bind('mouseenter', function() {
				termY = $(document).scrollTop();
				
				$(this).bind('mousemove',function(){
					$(document).bind('mousemove',function(event) {
						posX = event.pageX;
						posY = event.pageY;
					});
					//var de=posY.toString().indexOf('px'); //문자로 반환안함
					var de = posY;
					
					$(this).parent().next().css('left',(posX-15)+"px");
					$(this).parent().next().css('top',(posY-88-termY)+"px");
					$(this).parent().next().css('display','block');
				});
			})
			.bind('mouseleave', function() {
				$(this).parent().next().css('display','none');
			});
		},

		/*REPORT TOOLTIP*/
		toolTip2:function(){
			var posX;
			var posY;
			var termY;
			this.bind('mouseenter', function() {
				termY = $(document).scrollTop();
				
				$(this).bind('mousemove',function(){
					$(document).bind('mousemove',function(event) {
						posX = event.pageX;
						posY = event.pageY;
					});
					//var de=posY.toString().indexOf('px'); //문자로 반환안함
					var de = posY;
					
					if($(this).hasClass('elec')){
						$(this).parent().parent().parent().find('.tip_gas').css('display','none');
						$(this).parent().parent().parent().find('.tip_elec').css('left',(posX-15)+"px");
						$(this).parent().parent().parent().find('.tip_elec').css('top',(posY-88-termY)+"px");
						$(this).parent().parent().parent().find('.tip_elec').css('display','block');
					}else if($(this).hasClass('gas')){
						$(this).parent().parent().parent().find('.tip_elec').css('display','none');
						$(this).parent().parent().parent().find('.tip_gas').css('left',(posX-15)+"px");
						$(this).parent().parent().parent().find('.tip_gas').css('top',(posY-88-termY)+"px");
						$(this).parent().parent().parent().find('.tip_gas').css('display','block');
					}
				});
			})
			.bind('mouseleave', function() {
				$(this).parent().parent().parent().find('.tip_elec').css('display','none');
				$(this).parent().parent().parent().find('.tip_gas').css('display','none');
			});
		},

		/*main : 하단 뉴스 배너*/
		newsMove:function(){
			
			var _this = jQuery(this);
			var btn = _this.find('.rss_btn');
			var bTime = 0;
			var bTimer = 3000;
			var moveHei = 14;
			var len = _this.find('ul').find('li').length-1;
			var btnState = false;
			
			if(len == 0){return;}
			function moving()
			{
			
				var objDiv  = "<li>" +  _this.find('ul').find('li').eq(0).html() + "</li>";	
				jQuery(objDiv).insertAfter(  _this.find('ul').find('li').eq(len));

				_this.find('ul').stop().animate({
					'margin-top':-1*moveHei + "px"	
						
				},500, function(){
					 _this.find('ul').find('li').eq(0).remove();
					_this.find('ul').stop().animate({"margin-top": 0 + "px"},0);
					btnState = false;
				})

			};//E 
			
			
			bTime = setInterval(moving, bTimer);

			btn.bind('click mouseleave', function(e){
				
				if(e.type == "click")
				{
					if(!btnState)
					{
						clearInterval(bTime);		
						moving();
						btnState = true;
					};//E if
					
				} else if(e.type == "mouseleave")
				{
					bTime = setInterval(moving, bTimer);
				};//e if
				return false;
			});
		}
	});

	jQuery('.graphBox .graphBar').toolTip();
	jQuery('.graphBox .elec').toolTip2();/* report tooltip */
	jQuery('.graphBox .gas').toolTip2();/* report tooltip */	
	jQuery('.grap .realData').toolTip(); /*main tooltip*/
	//jQuery('.rss').newsMove();/*main rss news*/

	/* sub - 차트 데이터 tooltip */
	$('.tableTooltip a')
		.bind('mouseenter', function() {
			$(this).next().css('display','block');
		})
		.bind('mouseleave', function() {
			$(this).next().css('display','none');
		});

	/* sub - 테이블 속성 주기 */
	$('.table_style01_02 tbody tr:odd td').css('background','#fafafa');
	$('.table_style01_02 tfoot td').css('background','#fef4f2');

	$('.table_style01_03 tbody tr:nth-child(4n-1) td').css('background','#fafafa');
	$('.table_style01_03 tbody tr:nth-child(4n) td').css('background','#fafafa');
	$('.table_style01_03 tfoot td').css('background','#fef4f2');

	/* 131202_FAQ - 슬라이드 토글_수정 */
	/* 131129_FAQ - 슬라이드 토글 */
	$('.faq .cellStyle a').bind('mousedown',function () {
		if($(this).parent().parent().hasClass('trStyle02')){
			$(this).parent().parent().removeClass('trStyle02');
			$(this).parent().parent().next('.trStyle').hide();
		} else {
			$('.faq .cellStyle a').each(function(){
			$(this).parent().parent().next('.trStyle').hide();
			if($(this).parent().parent().hasClass('trStyle02')){
					$(this).parent().parent().removeClass('trStyle02');
				}
			})
			$(this).parent().parent().next('.trStyle').show();
			$(this).parent().parent().addClass('trStyle02');
		};//E if
	});
	/* //131202_FAQ - 슬라이드 토글_수정 */

	/* 131202_고객센터 - focus시, value값 없애기_추가 */
	$('.input_style02.cs').bind('focusin', function() {
		
		jQuery(this).attr('value','');
	}). bind('focusout', function(){
		var str = jQuery(this).attr('value');
	
		if(str == ""){
			jQuery(this).attr('value', '제목 및 내용을 입력하세요.');
		} else {
			
		};//E if
	});
	/* //131202_고객센터 - focus시, value값 없애기_추가 */

	/*select Box z-index 설정*/
	var zLen = 0;
	var zIndex = 100;
	$('select[id^=country_]').each(function()
	{
			zLen ++;
		
	})

	function selectZindex()
	{
		
		for( i = 0; i < zLen; i++)
		{
			$('select[id^=country_]').eq(i).parent().attr('style',"z-index:"+(zIndex - i)+';');
		};//E for

	}
	
	selectZindex();

	

});

/* 20131128 hjl 에너지관리 peak001*/
function peakTextSet(){
	var wid = jQuery(window).width();
		
	var txt=$('div.energy_use div.target_energy div.text');
	var input=$('div.energy_use div.target_energy div.targetEn_input');
	

	if(wid >= 1600){
		txt.width(310);
		txt.css('padding','14px 9px 14px 106px'); 
		txt.css('background-position-x', 'left');
		
		input.width(311);
		input.children('form input:text').attr('size',278);

	}else{
		txt.width(311);
		txt.css('padding','14px 9px'); 
		txt.css('background-position-x', 'right');

		input.width(217);
		input.children('form input:text').attr('size',181);
	}
}

function setLayout() {
	if (!printMode)
	{
		try{
			var winWidth = jQuery(window).width();
			var docWidth = jQuery(document).width();
			var lnbWidth = 200;
			var contentMargin = 0;
			var contentWidth = winWidth - lnbWidth - contentMargin;
			jQuery("#container").css("width",docWidth);


			if (winWidth <= 1000) {
				contentWidth = 800;
			}else if (winWidth <= 1600) {
				// contentWidth = winWidth-lnbWidth-contentMargin;
			}else {
				contentWidth = 1600-lnbWidth-contentMargin;
			}
			jQuery("#container").css( {"width": contentWidth+lnbWidth+contentMargin+'px'});
			jQuery("#contents").css( {"width":contentWidth + "px"});


			var rpFixedlayerWidth = jQuery(".fixed_layout").width();

			if (rpFixedlayerWidth <= 1290) {
				rpFixedlayerWidth = 1290;
				jQuery(".fixed_layout").css( {"width": rpFixedlayerWidth + 'px',"overflow":'hidden' });
			}
		}catch (e) {
			alert (e);
		}
	}
}

var printMode = 0;
function setPrintMode (onOff) {
	if (onOff == 1)
	{
		printMode = 1;
		var hideElem = ['.conPosDiv', 'header', '.lnb',  '.clear', 'footer'];
		jQuery("#wrap").attr("id", "wrap1");
		for (i=0; i<hideElem.length ;i++ )
		{
			jQuery(hideElem[i]).css("display","none");
		}
		jQuery("#container").css("width","800px");
		jQuery("#contents").css("width","800px");
		jQuery(".table table_id_4").css("width","800px");
		jQuery(".BoxArea").css("margin","20px 0 0 0");
		
	}
	else
	{
		printMode = 0;
		var hideElem = ['.conPosDiv', 'header', '.lnb', '.clear', 'footer'];
		jQuery("#wrap1").attr("id", "wrap");
		for (i=0; i<hideElem.length ;i++ )
		{
			jQuery(hideElem[i]).css("display","");
		}
		jQuery("#container").css("width","");
		jQuery("#contents").css("width","");
		jQuery(".table table_id_4").css("width","800px");
		jQuery(".BoxArea").css("margin","20px 30px 0 30px");
		
	}
}


jQuery(document).ready(function() {
	setLayout();
	peakTextSet();
	jQuery(window).resize(function() {
		setLayout();
		peakTextSet();
	});	
	


	/*131129 jhy footer topBtn*/
	jQuery('footer .btn_top').bind('mousedown', function(){
		jQuery('html, body').stop().animate({scrollTop: 0}, 200  );
		return false;
	});

});


jQuery('document').ready(function() {
	jQuery(".input_style03").attr("placeholder", "입력"); 

	jQuery(".input_style03").bind('focus', function(){
		jQuery(this).attr('placeholder', '');
	});
	jQuery(".input_style03").bind('blur', function(){
		jQuery(this).attr('placeholder', '입력');
	});
});

/*Loading*************************************************************************************************/
function showLoading(onOff, selectors){
	jQuery(selectors).each(function(sidx, selector){
		var divWidth = (jQuery(selector).width());
		var divHeight = (jQuery(selector).height());

		if (onOff == '1')
		{
			jQuery(selector).append ("<div class='divLoading' style='position:absolute; width:"+divWidth+"px; height:"+divHeight+"px; padding:0; margin:0;left:0; top:0; background:#FFF; text-align:center;'></div>");
			jQuery(selector).append ("<div class='divLoadingContent' style='position:absolute; padding:0; margin:0;left:0; top:0; text-align:center; line-height:20px;'><img src='/images/common/loading.gif' style='margin:0 0 8px 0;'/><br>"+"<p style='text-aling:center;'>요청하신 작업을 처리하고 있습니다.<br/> 잠시만 기다리세요."+"</div>");
			jQuery(selector).find(".divLoading").fadeTo(0, 0.7);
		}
		else
		{
			jQuery(selector).find(".divLoading").remove();
			jQuery(selector).find(".divLoadingContent").remove();
		}
		var divContentWidth = (jQuery(selector).find(".divLoadingContent").width());
		var divContentHeight = (jQuery(selector).find(".divLoadingContent").height());
		var posX = (divWidth/2) - (divContentWidth/2);
		var posY = (divHeight/2) - (divContentHeight/2);
		jQuery(selector).find(".divLoadingContent").css("left", posX+"px");
		jQuery(selector).find(".divLoadingContent").css("top", posY+"px");
		
	});
}
